<?php
session_start();
ob_start();
require_once "includes/config.php";
require_once "includes/functions.php";

if(empty($_GET['sid'])) {
	header("Location:index.php?notFound");
}

$sid = $_GET['sid'];

$sqlChkStore = "SELECT * FROM tbl_seller_store WHERE seller_id='$sid'";
$rstChkStore = mysql_query($sqlChkStore) or die(mysql_error());
if(mysql_num_rows($rstChkStore)==0) {
	header("Location:index.php?store=$sid");
}

//check user session
$user = checkSession();
$userId= $user['id'];
$userName= $user['name'];
$userType= $user['type'];
	

 if(!empty($_GET['sid'])) { 
	 $sqlSelStore="SELECT * FROM tbl_seller_store WHERE seller_id=".$_GET['sid'];
	 $rstSelStore=mysql_query($sqlSelStore);
	 $rowSelStore=mysql_fetch_array($rstSelStore);
	 $storeId = $rowSelStore['seller_store_id'];
	 $sellerName=$rowSelStore['seller_name'];
	 $storeName=$rowSelStore['store_name'];
	 $storeDescription=$rowSelStore['store_description'];
	 $storeLogo=$rowSelStore['store_logo'];
	 $storeThumb=$rowSelStore['store_image_thumb'];
	 
	 $storeGuidelines=$rowSelStore['store_guidelines'];
	 $newsletterSettings=$rowSelStore['newsletter_settings'];
	 $offerSettings=$rowSelStore['offer_settings'];
	//$offerSettings=0;
	 $offer=$rowSelStore['offer'];
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php

 echo "Swapen.com - ".ucfirst($sellerName)."'s Store";

?>
</title>
<script src="js/spry/SpryTabbedPanels.js" type="text/javascript"></script>
<link href="js/spry/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
background-color:#fafafa;
margin:0; padding:0;
}
.boldGrey{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
font-weight:bold;
color:#666666;
}
/*a:link{
text-decoration:underline;
color:#0711C0
}
a:visited{
text-decoration:underline;
color:#0711C0
}
a:hover{
text-decoration:none;
color:#FF8000
}
a:active {
color:#FF8000
}
.noDecorLink:link{
text-decoration:none;
border:none;
outline:none;

}*/
.header{
background-image:url(../images/header.jpg);
}
.container{
border-collapse:collapse; border-bottom-width:thin; border-left-width:thin; border-right-width:thin; border-top-width:thin;border-bottom-color:#999999;border-top-color:#999999;border-right-color:#999999;border-left-color:#999999;
}
.contentHeader
{
font-weight:bold;text-indent:10px; color:#204AFE; background-image:url(images/grey_radiant_header.jpeg);
}
.content{
line-height:20px;
text-align:justify;
padding-left:10px;
padding-right:10px;
}
.contentForm{
line-height:20px;
text-align:justify;
}
#footer 
{
	background:#FFFFFF none repeat scroll 0 0;
	border-top:3px solid #EEEEEE;
	clear:both;
	padding:5px;
}
ul#navFooter 
{
	height:15px;
	margin:0 auto;
	text-align:center;
}
ul#navFooter li 
{
	display:inline;
	list-style-image:none;
	list-style-position:outside;
	list-style-type:none;
	margin:0 2px;
}
ul#navFooter li,
ul#navFooter li a:link,
ul#navFooter li a:active,
ul#navFooter li a:visited,
ul#navFooter li a:hover
{
	font: 11px/25px Verdana, Arial, Helvetica, sans-serif; 
	color:#999;
}
ul#navFooter li a:hover
{
	text-decoration: underline; 
	color:#609629;
}
p#copyright 
{
	-x-system-font:none;
	color:#999999;
	font-family:Verdana,Arial,Helvetica,sans-serif;
	font-size:11px;
	font-size-adjust:none;
	font-stretch:normal;
	font-style:normal;
	font-variant:normal;
	font-weight:normal;
	/*line-height:25px;*/
	margin-top:20px;
	text-align:center;
}

span#listed-in { margin:2px; font-size:10px; padding:2px; }

.fieldWidth { width:210px; padding:1px}

#err-msg { color:#FF0000; padding:10px; border:1px solid #CCC; }
#suc-msg { color:#0000CC; padding:10px; border:1px solid #CCC; }

.head-tr { 		
		background:transparent url(images/greytile.png) repeat scroll 0 0;
	}
.head-tr td { padding-bottom:5px; padding-top:5px; padding-left:2px }

.errorField {color:#FF0000; font-weight:bold; }
div#panel { border:1px solid #CCC; margin:0; padding:0; }
.boldGreyNotes{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
color:#666666;
}
.blueContentHeader{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
color:#FFFFFF;
background-color:#0FB6FA;
}
.greyBoldCell{
background-color:#E6E6E6;
padding-left:5px;
font-weight:bold;
}
.paddingLeftCell{
padding-left:5px;
}
</style>
<script type="text/javascript" src="js/functions.js"></script>


<link href="includes/style.css" rel="stylesheet" type="text/css" />

</head>

<body>

<?php 
	$user = checkSession();
	$userId= $user['id'];
	$userName= $user['name'];
	$userType= $user['type'];
	//echo $_SESSION['user_type_sess'];
?>

<table width="950" border="0" align="center" bgcolor="#FFFFFF">
  <tr>
    <td height="119"><?php include_once "header1.php";?></td>
  </tr>
 <!--  <tr>
    <td>
      <table width="100%"  border="0" align="center">
        <tr>
          <td width="60%">&nbsp;</td>
          <td width="40%" align="right">><?php include("search_panel.php"); ?></td>
        </tr>
      </table></td>
  </tr> -->
 
  <tr>
    <td height="193"  class="container"><table width="100%" border="0">
      <tr>
        <td height="119" colspan="2" valign="top">
		
		<div id='panel' style="border:none;">
			<div class="fullbox2_top"></div>
			<div class="fullbox2_repeat">
		<table width="100%" border="0">
          <tr>
            <td class="contentHeader">
			<div class="sellname"><h2><?php echo $storeName; ?></h2></div>
			
			<div class="selldesc">
			<table width="100%" border="0">
				<tr>
					<td width="10%"><img src="<?php echo $storeThumb; ?>" alt=""></td>
					<td width="90%" valign="top"><strong><?php echo $storeDescription; ?></strong></td>
				</tr>
				<tr>
				  <td colspan="2">
				  	<?php 
						if($_GET['sid']==$userId) {
						?>							
							<span style="font-weight:bold;"><a href="index.php?updstore=<?php echo $storeId; ?>">Update Store</a></span>							
						<?php } ?>
						
				  </td>				  
				 </tr>
			</table>
			
			<div style="width:100%; float:left;">
				<div class="selldesc_in" style="margin:0px 0px 0px 10px;"><br />
					<font style="color:#767676; font-size:12px; font-weight:normal;">Free Gift with EVERY Purchase</font><br />
					<font style="color:#d80101; font-size:12px; font-weight:normal;">$19.99 VALUE</font><br />
					<font style="color:#000000; font-size:12px; font-weight:normal;">Multi Content Playback with SD Memory Card</font>
				</div>
				<div class="selldesc_in">
					<img src="images/sd_memorycard.png" style="width:200px; height:112px;" />
				</div>
			</div>
			
			</div>
			</td>
          </tr>
        </table>
			</div>
			<div class="fullbox2_bot"></div>
		</div>
		</td>
      </tr>
	  
	   <tr>
        <td height="119" colspan="2" valign="top">
		
		<div id='panel' style="border:none;">
			<div class="fullbox2_top"></div>
			<div class="fullbox2_repeat">
				<div class="fulldiv" style="text-align:center;">
					Featured Store Products
				</div>
			</div>
			<div class="fullbox2_bot"></div>
		</div>
		</td>
      </tr>
	  
	  
	   <tr>
        <td colspan="2" valign="top">
		
		<div id='panel' style="border:none;">
			<a href="#"><img src="images/arrow_back.png" style="border:none; margin:0px 5px 0px 0px;" />Back to Search Results</a>
		</div>
		</td>
      </tr>
	  
	  
      <tr>
        <td height="16" colspan="2" valign="top">&nbsp;</td>
        </tr>
      <tr>
	  	<td>
		<div style="width: 950px; float: left; vertical-align: top;">
		
		<div class="mypg_left_out">
		<table style="width:100%">
		<tr>
			<td>
				<div class="fulldiv">
					<p style="color:#000000; font-size: 12px; font-weight: normal;">
					Nook Store<br />
					1545 N Sunset Blvd<br />
					Los Angeles CA 90048
					</p>
				</div>
			</td>
		</tr>
		<tr>
        	<td width="214" valign="top">
			<p style="color:#767676; font-size: 14px; font-weight: normal; margin:5px 0px 5px 0px;">
				Refine Search
			</p>
			<div class="shourtbox">
			<table width="100%" border="0">
        <?php if($offerSettings)
		{
		?>
        <tr>
            <td><table width="212"  border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td></td>
              </tr>
              <tr>
                <td style=" background-image:url(images/LHS_menu_top.jpg); height:10px"></td>
              </tr>
              <tr>
                <td height="30" style=" background-image:url(images/LHS_gradient_bg.jpg); background-repeat:repeat-y;height:100px; vertical-align:top;"><div id="category-title">Offer from <?php echo $sellerName; ?> </div>
                    <br />
                  <div id="category-content"><?php echo $offer; ?></div>
                  </td>
              </tr>
              <tr>
                <td style=" background-image:url(images/LHS_menu_bottom.jpg); height:18px"></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <?php } ?>
          <tr>
            <td><table width="212"  border="0" cellpadding="0" cellspacing="0">
						  
              <tr>
                <td style="vertical-align:top;">
				<div id="category-title">Search Within Store</div>
                    <br />
                  <div class="fulldiv">
				  <center>
                    <form action="" method="post" name="formShopSearch" id="formShopSearch">
                        <input type="text" name="search_string" id="search_string" class="inputbg" style="width:120px; float:left;" />
                        <input type="submit" name="search" value="Search" class="yellow_btn" style="height:30px; margin:0px 0px 0px 10px;" />
                      </form>
                  </center>
				  </div>
				 </td>
              </tr>
			   
			  <tr>
                <td style="vertical-align:top;"><br /> <br />
				<div id="category-title">Sub-Category</div>
                    <br />
                  
                    <form action="" method="post" name="formShopSearch" id="formShopSearch">
						<select class="inputbg" style="width:150px;">
							<option>DVD Players</option>
							<option>DVD Players1</option>
							<option>DVD Players2</option>
							<option>DVD Players3</option>
							<option>DVD Players4</option>
						</select>
                    </form><br /> <br />
                 
				 </td>
              </tr>
			   
			  <tr>
                <td style="vertical-align:top;">
				<div id="category-title">By Price</div>
              	<p><a href="#">under - $10</a></p>  
				<p><a href="#">$10 - $50</a></p>  
				<p><a href="#">$50 - $100</a></p>  
				<p><a href="#">$100 - $500</a></p> 
				<p><a href="#">$500 +</a></p>           
				 </td>
              </tr>
              
            </table></td>
          </tr>
        </table>
			</div>
			</td>
		</tr>
		
		<tr>
        	<td width="214" valign="top">
			<p style="color:#767676; font-size: 14px; font-weight: normal; margin:5px 0px 5px 0px;">
				Classifieds
			</p>
			<div class="shourtbox">
			<table width="100%" border="0">
        
          	<tr>
            
                <td style="vertical-align:top;">
				<?php /*?><div id="category-title">By Price</div><?php */?>
              	<p><a href="#">Jobs - 1</a></p>  
				<p><a href="#">Classifieds - 4</a></p>            
				</td>
			
          </tr>
        </table>
			</div>
			</td>
		</tr>
		
		</table>
		</div>
		
		<div class="fullbox_out">
		<table style="width:100%">
		<tr>
       		<td width="99%" height="300" style="vertical-align:top;">
			<div id='panel' style="border:none; width:700px;">
			
			<div class="fulldiv" style="width:700px;">
 			<strong class="orangehead">&nbsp;&nbsp;Product sale by <?php echo $sellerName;?></strong>
 
 	
	
	<div class="fulldiv" style="width:700px;">
	
	<div class="fulldiv" style="margin: 10px 0px 0px;">
		<?php       
	   if(!empty($_GET['sid']))
	   {
	   require_once "includes/pagination.php";
	   $itemPerPage=10;
	   $pagelink="sid=".$_GET['sid'];
		  
	    $sqlSelPro="SELECT DISTINCT tbl_items.*, tbl_product.product_name,tbl_product.selling_type,tbl_product.selling_type,  tbl_product.shipping, tbl_users.user_id 
					FROM tbl_product, tbl_items, tbl_users 
					WHERE tbl_product.product_id = tbl_items.product_id AND 	 	
					 	  tbl_users.user_id=tbl_items.seller_id";	
		/*
	   if(!empty($_GET['cat']))
				$sqlSelPro.=" AND tbl_product.category_id=".$_GET['cat'];*/
	   if(!empty($_POST['search_string']))
				$sqlSelPro.=" AND tbl_product.product_name LIKE '%".$_POST['search_string']."%'";
		
		$sqlSelPro.= " AND tbl_users.user_id='$userId'";
		  
	    if(!empty($_GET['sortby'])) {
			if($_GET['sortby']=='lps') {
				$sqlSelPro .= " order by tbl_items.price ASC, tbl_product.shipping ASC";		
			}
			else if($_GET['sortby']=='hps') {
				$sqlSelPro .= " order by tbl_items.price DESC, tbl_product.shipping DESC";		
			}
			else if($_GET['sortby']=='bm') {
				$sqlSelPro .= " order by field(tbl_product.product_name, '$key') DESC";		
			}
			else if($_GET['sortby']=='online') {
				$sqlSelPro .= " order by field(tbl_product.selling_type, 'online') desc";		
			}
			else if($_GET['sortby']=='local') {
				$sqlSelPro .= " order by field(tbl_product.selling_type, 'local') desc";		
			} 
			 $sqlSelPro .=", tbl_items.bargain_duration DESC";	
	   } else { 
			$sqlSelPro .=" ORDER BY tbl_items.bargain_duration DESC";	
	   }
	   	   						
		$rstSelPro=mysql_query(getPagingQuery($sqlSelPro,$itemPerPage));			  
		$num=mysql_num_rows($rstSelPro);
		//$num=0;
		if($num==0){
			?><div class="fulldiv">
				<div class="fullbox_top"></div>
				<div class="fullbox_repeat">
		  <?php echo "&nbsp;&nbsp;No Products Found..."; ?>
		    </div>
				<div class="fullbox_bot"></div>
			</div>
			
	    <? } else {	?>
		    
			<table align="center" width="100%" border="0">
				<tr>
					<td width="15%" style="color:#666666;">Sort Options:</td>
					<td width="15%"><a href="seller_store.php?<?php echo $pagelink; ?>&sortby=bm">Best Match</a></td>
					<?php /*?><td width="25%"><a href="seller_store.php?<?php echo $pagelink; ?>&sortby=lps">Lowest Price and Shipping</a></td>
					<td width="25%"><a href="seller_store.php?<?php echo $pagelink; ?>&sortby=hps">Highest Price and Shipping</a></td><?php */?>					
					<td width="15%"><a href="seller_store.php?<?php echo $pagelink; ?>&sortby=local">Local Only</a></td>
					<td width="15%"><a href="seller_store.php?<?php echo $pagelink; ?>&sortby=online">Online only</a></td>
					<td width="30%">
						<div class="greytab_out" style="margin:0px 5px -9px 5px;">
							<div class="greytab_left">&nbsp;</div>
							<div class="greytab_repeat">Sort</div>
							<div class="greytab_right">&nbsp;</div>
						</div>
					</td>
				</tr>
			</table>
	</div>
		
	</div>
	<?
	    while($rowSelPro=mysql_fetch_array($rstSelPro))  {
					 
					   $productId=$rowSelPro['product_id'];
					   $itemId=$rowSelPro['item_id'];
					   $productName=wordFormater($rowSelPro['product_name'],20);
					   $productTitle = $rowSelPro['product_name'];
										   
					   $productPrice=number_format($rowSelPro['price'],0);
					   $productCommission=number_format($rowSelPro['commission'],0);
					   
					   $postedDate=$rowSelPro['posted_date'];
					   $bargainDate = $rowSelPro['bargain_duration'];
					   $timeLeft = getRemainingTime($bargainDate);
					  
					   $pimage = getProductImage($itemId,'i');
					   
					   if($pimage['thumb']!="") {
							$productThumb = $pimage['thumb'];
					   }  else {
							$productThumb="images/no_image.gif";	
					   }
					  //echo $timeLeft;
					   if($timeLeft==0) {
						        $today=getdate();
							//$d= mktime(0,0,0,$today['mon'],$today['day']+32,$today['year']);
							 $d = mktime(0, 0, 0, date('m'), date('d')+30, date('Y'));
							$bargin= date('Y-m-d h:i:s',$d);
							$sql=mysql_query("update tbl_items set bargain_duration='".$bargin."' where item_id='".$itemId."'") or mysql_error();;
							
							//$timeLeft = "<font color='red'>Listing Expired</font>";								
					   }
	?>
			<div class="fulldiv">
				<div class="fullbox_top"></div>
				<div class="fullbox_repeat">
					<div class="sellpro_table">
						<div class="sellpro_row1">
							<img src="images/sample_product.png" />
						</div>
						<div class="sellpro_row2">
							<p class="sellpro_head" style="margin:5px 0px 5px 0px;">
							Panasonic Blue Ray Player
							</p>
							<i>product owner - Bjpen15</i>
							<i>local pick up - <font style="color:#000000;">available</font></i>
						</div>
						<div class="sellpro_row2" style="text-align:center;">
							<img src="images/m.png" />
							<p>
								<i>miles away - <font style="color:#000000;">5 miles</font></i>(<a href="#">map it</a>)
							</p>
						</div>
						<div class="sellpro_row3" style="text-align:right;">
							<p class="redtxt" style="margin:5px 0px 5px 0px;">$189.95</p>
							<p style="margin:5px 0px 5px 0px;"><i>$189.95</i></p>
							<p style="margin:5px 0px 5px 0px;"><a href="#" style="font-size:14px; font-weight:bold;">ADD TO CART</a></p>
						</div>
					</div>
				</div>
				<div class="fullbox_bot"></div>
			</div>	
	<?
	    }
	?>
			
			<table width="100%" border="0">
         <tr>
           <td height="110">
			
		<?php		   
				
				
				echo "";
				echo "<br><table width='650' border='0' align='center' cellspacing='0'>";
				echo "<tr class='head-tr'>
						  <td height='25' width='120'>&nbsp; </td>
						  <td width='250'> <strong>Product name </strong></td>
						  <td width='5'> &nbsp; </td>
						  <td width='150'> <strong>Price+Commission</strong> </td>
						  <td width='165'><strong>Time Left</strong> </td>
						</tr>";
				  	 while($rowSelPro=mysql_fetch_array($rstSelPro))  {
					 
					   $productId=$rowSelPro['product_id'];
					   $itemId=$rowSelPro['item_id'];
					   $productName=wordFormater($rowSelPro['product_name'],20);
					   $productTitle = $rowSelPro['product_name'];
										   
					   $productPrice=number_format($rowSelPro['price'],0);
					   $productCommission=number_format($rowSelPro['commission'],0);
					   
					   $postedDate=$rowSelPro['posted_date'];
					   $bargainDate = $rowSelPro['bargain_duration'];
					   $timeLeft = getRemainingTime($bargainDate);
					  
					   $pimage = getProductImage($itemId,'i');
					   
					   if($pimage['thumb']!="") {
							$productThumb = $pimage['thumb'];
					   }  else {
							$productThumb="images/no_image.gif";	
					   }
					  //echo $timeLeft;
					   if($timeLeft==0) {
						        $today=getdate();
							//$d= mktime(0,0,0,$today['mon'],$today['day']+32,$today['year']);
							 $d = mktime(0, 0, 0, date('m'), date('d')+30, date('Y'));
							$bargin= date('Y-m-d h:i:s',$d);
							$sql=mysql_query("update tbl_items set bargain_duration='".$bargin."' where item_id='".$itemId."'") or mysql_error();;
							
							//$timeLeft = "<font color='red'>Listing Expired</font>";								
					   }
										   
					   echo "<tr>
							<td height='106'>
								<div align='center'><img src='$productThumb'></div>
							 </td>								 
							 <td style='vertical-align:top; padding:10px;'> <a href='index.php?products=$itemId
							 ' title='$productTitle'> $productName </a> </td>
							 <td style='vertical-align:top; padding:10px;'> &nbsp; </td>
							 <td style='vertical-align:top; padding:10px;'> $".$productPrice." + ".$productCommission." </td>
							 <td style='vertical-align:top; padding:10px;'> $timeLeft </td>
						   </tr>";	
						echo "<tr>
								 <td colspan='5'> <div style='border-top:1px solid #CCCCCC;'> </div> </td>
							  </tr>";				 	
					 }					 
					 echo " </table>";
					 
				} 	
	}			
	?></td>
    </tr>
    <tr>
    <td><div align="center"><?php
				   //$pagelink="sid=".$_GET['sid'];
				   echo $disp=getPagingLink($sqlSelPro,$itemPerPage,$pagelink);							   
			 ?></div>
			</td>
         </tr>
       </table>
	   		
			
			</div>
			
	   		</div>
	   		</td>
	   	</tr>
		</table>
	   	</div>
		
	   	</div>
	   	</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="80"><?php include_once "footer.php";?></td>
  </tr>
</table>
</body>
</html>